package org.example.myleet.p708;

public class Node {
    public int val;
    public Node next;

    public Node() {}

    public Node(int _val) {
        val = _val;
    }

    public Node(int _val, Node _next) {
        val = _val;
        next = _next;
    }

    @Override
    public String toString() {
        Node cur = this;
        StringBuilder sb = new StringBuilder();
        sb.append(cur.val);
        cur = cur.next;
        int cnt = 0;
        while (null != cur && this != cur && cnt < 100) {
            sb.append(',').append(cur.val);
            cur = cur.next;
            ++cnt;
        }
        return sb.toString();
    }
}
